using System;
using System.Collections.Generic;
using System.Text;
using usm.SolDev.Common;

using System.Xml.Serialization;

namespace usm.SolDev.Common.Config
{
    [Serializable]
    public class UserLoginConfig : Configuration
    {
        #region Private properties
        private string login = "user";
        private string password = Cryptography.CryptRSA("");
        #endregion

        #region C'tros
        /// <summary>
        ///     Default  constructor
        /// </summary>
        public UserLoginConfig () {}

        /// <summary>
        ///     Initialization constructor
        /// </summary>
        /// <param name="login">user login (will be trimmed out)</param>
        /// <param name="password">user password</param>
        public UserLoginConfig (string login, string password)
        {
            this.login = login.Trim();
            this.password = Cryptography.ComputeHashWithSHA256(password);
        }
        #endregion

        #region Public properties]
       /// <summary>
        ///     Stores or returns user login
        /// </summary>
        [XmlAttributeAttribute(DataType = "string")]
        public string Login
        {
            get { return login; }

            set
            {
                if (value == null || value.Trim().Length == 0)
                {
                    throw new SolDevException(SolDevExceptionKey.UserLoginCannotBeEmpty);
                }

                login = value;
            }
        }

        /// <summary>
        ///     Hold's the user's password (encrypted). The assignment operation
        /// will not change password. The password is hold encrypted. Encryption is
        /// performed in constructor (when object is created and initialized)
        /// </summary>
        [XmlAttributeAttribute(DataType = "string")]
        public string Password
        {
            get { return password; }
            set
            {
                password = value;
            }
        }
       #endregion

    }
}
